package com.ruoyi.project.custom.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.custom.domain.CustomContact;
import com.ruoyi.project.custom.domain.CustomInfo;
import com.ruoyi.project.custom.domain.CustomOperator;
import com.ruoyi.project.custom.domain.vo.AbandonVo;
import com.ruoyi.project.custom.domain.vo.CustomImportVo;
import com.ruoyi.project.custom.domain.vo.CustomOperatorVo;
import com.ruoyi.project.custom.domain.vo.HandoverParamVo;
import com.ruoyi.project.custom.service.ICustomContactService;
import com.ruoyi.project.custom.service.ICustomInfoService;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.service.ISysDictDataService;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 【客户信息】Controller
 * 
 * @author ruoyi
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/custom/info")
public class CustomInfoController extends BaseController
{
    @Autowired
    private ICustomInfoService customInfoService;
    @Autowired
    ICustomContactService customContactService;
    @Autowired
    ISysDictDataService dictDataService;

    /**
     * 查询【客户信息】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomInfo customInfo)
    {
        startPage();
        List<CustomInfo> list = customInfoService.selectCustomInfoList(customInfo);
        return getDataTable(list);
    }

    @GetMapping("/selectOperatorShop")
    public TableDataInfo selectOperatorShop(CustomInfo customInfo)
    {
        startPage();
        List<CustomInfo> list = customInfoService.selectOperatorShop(customInfo);
        return getDataTable(list);
    }

    @GetMapping("/selectLeaderShop")
    public TableDataInfo selectLeaderShop(CustomInfo customInfo)
    {
        startPage();
        List<CustomInfo> list = customInfoService.selectLeaderShop(customInfo);
        return getDataTable(list);
    }

    @GetMapping("/selectNotAllocatedCustomList")
    public TableDataInfo selectNotAllocatedCustomList(CustomInfo customInfo)
    {
        startPage();
        List<CustomInfo> list = customInfoService.selectNotAllocatedCustomList(customInfo);
        return getDataTable(list);
    }

    @GetMapping("/selectMySignedCustomList")
    public AjaxResult selectMySignedCustomList()
    {
        return AjaxResult.success(customInfoService.selectMySignedCustomList(new CustomInfo()));
    }

    @PostMapping("/importExcel")
    public AjaxResult importExcel(MultipartFile file)
    {
        JSONObject retJson = new JSONObject();
        if(file.isEmpty()){
            return AjaxResult.error("文件为空！");
        }
        String oldFileName = file.getOriginalFilename();
        if(oldFileName ==null) {
            return AjaxResult.error("请上传正确格式的excel！");
        }
        if (!(oldFileName.toLowerCase().endsWith("xls") || oldFileName.toLowerCase().endsWith("xlsx"))){
            return AjaxResult.error( "请上传正确格式的excel");
        }

        try{
            List<CustomImportVo> list = null;
            ExcelUtil<CustomImportVo> util = new ExcelUtil<>(CustomImportVo.class);
            list = util.importExcel(null, file.getInputStream(), 1, 0);
            if (list == null || list.size() == 0){
                return AjaxResult.error( "excel 数据为空");
            }

            List<String> errList = new ArrayList<>();
            for(int i = 0; i < list.size(); i++){
                CustomImportVo c = list.get(i);
                StringBuilder rowErrMsg = new StringBuilder(256);
                // 校验客户来源
                if(StringUtils.isEmpty(c.getSourceType())){
                    rowErrMsg.append("客户来源必须选择；");
                }
                else{
                    switch (c.getSourceType())
                    {
                        case "默认":
                            c.setSourceType("0");
                            break;
                        case "新媒体-主动":
                            c.setSourceType("1");
                            break;
                        case "新媒体-截流":
                            c.setSourceType("2");
                            break;
                    }
                    if(!"0".equals(c.getSourceType()) && !"1".equals(c.getSourceType()) && !"2".equals(c.getSourceType())){
                        rowErrMsg.append("客户来源不正确；");
                    }
                }

                // 校验微信账号
                if("1".equals(c.getSourceType()) && StringUtils.isEmpty(c.getWechatNo())){
                    rowErrMsg.append("客户来源为\"新媒体-主动\"时，微信账号不能为空；");
                }

                // 校验新媒体平台类型
                if(StringUtils.isNotEmpty(c.getMerchantPlatform())) {
                    SysDictData dictData = dictDataService.selectDictInfo("new_media_platform", c.getMerchantPlatform());
                    if (dictData == null) {
                        rowErrMsg.append("新媒体平台类型不正确；");
                    } else {
                        c.setMerchantPlatform(dictData.getDictValue());
                    }
                }

                // 校验店铺名称
                if("0".equals(c.getSourceType()) && StringUtils.isEmpty(c.getCusName())){
                    rowErrMsg.append("客户来源为\"默认\"时，店铺名称不能为空；");
                }

                if(rowErrMsg.length() > 0){
                    errList.add("第" + (i + 1) + "行：" + rowErrMsg.toString());
                }
            }

            if(errList.size() > 0){
                retJson.put("code", 0);
                retJson.put("msg", errList);
                return AjaxResult.success(retJson);
            }

            for(CustomImportVo c : list){
                CustomInfo customInfo = new CustomInfo();
                customInfo.setSourceType(c.getSourceType());
                customInfo.setWechatNo(c.getWechatNo());
                customInfo.setMerchantPlatform(c.getMerchantPlatform());
                customInfo.setMerchantAccount(c.getMerchantAccount());
                customInfo.setMerchantTel(c.getMerchantTel());
                customInfo.setCusname(c.getCusName());
                customInfoService.insertCustomInfo(customInfo);
            }
            retJson.put("code", 1);
            retJson.put("msg", "成功");
            return AjaxResult.success(retJson);
        }catch(Exception e){
            e.printStackTrace();
        }

        return AjaxResult.success();
    }

    /**
     * 导出【客户信息】列表
     */
    @Log(title = "导出客户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomInfo customInfo)
    {
        List<CustomInfo> list = customInfoService.selectCustomInfoList(customInfo);
        ExcelUtil<CustomInfo> util = new ExcelUtil<CustomInfo>(CustomInfo.class);
        return util.exportExcel(list, "客户信息");
    }

    /**
     * 获取【客户信息】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        CustomInfo customInfo = customInfoService.selectCustomInfoById(id);

        CustomContact customContact = new CustomContact();
        customContact.setCustomId(customInfo.getId());
        List<CustomContact> contacts = customContactService.selectCustomContactList(customContact);
        customInfo.setContacts(contacts);

        return AjaxResult.success(customInfo);
    }

    @GetMapping("/getCustomAgreementList")
    public AjaxResult getCustomAgreementList()
    {
        return AjaxResult.success(customInfoService.selectCustomAgreementList());
    }

    @GetMapping("/selectMyCustomCount")
    public AjaxResult selectMyCustomCount(CustomInfo customInfo)
    {
        return AjaxResult.success(customInfoService.selectMyCustomCount(customInfo));
    }

    /**
     * 新增【客户信息】
     */
    @Log(title = "【新增客户信息】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomInfo customInfo)
    {
        if (UserConstants.NOT_UNIQUE.equals(customInfoService.checkCustomNameUnique(customInfo)))
        {
            return AjaxResult.error("新增客户'" + customInfo.getCusname() + "'失败，客户名称已存在");
        }
        return toAjax(customInfoService.insertCustomInfo(customInfo));
    }

    @Log(title = "【运营人员新增客户信息】", businessType = BusinessType.INSERT)
    @PostMapping("/insertCustomByOperator")
    public AjaxResult insertCustomByOperator(@RequestBody CustomInfo customInfo)
    {
        if (UserConstants.NOT_UNIQUE.equals(customInfoService.checkCustomNameUnique(customInfo)))
        {
            return AjaxResult.error("新增客户'" + customInfo.getCusname() + "'失败，客户名称已存在");
        }
        return toAjax(customInfoService.insertCustomByOperator(customInfo));
    }

    /**
     * 修改【客户信息】
     */
    @Log(title = "【编辑客户信息】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomInfo customInfo)
    {
        if (UserConstants.NOT_UNIQUE.equals(customInfoService.checkCustomNameUnique(customInfo)))
        {
            return AjaxResult.error("修改客户'" + customInfo.getCusname() + "'失败，客户名称已存在");
        }
        return toAjax(customInfoService.updateCustomInfo(customInfo));
    }

    /**
     * 删除【客户信息】
     */
    @Log(title = "【删除客户信息】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(customInfoService.deleteCustomInfoByIds(ids));
    }

    @Log(title = "将客户放入公海", businessType = BusinessType.UPDATE)
    @PostMapping("/abandonCustom")
    public AjaxResult abandonCustom(@RequestBody AbandonVo abandonVo)
    {
        return toAjax(customInfoService.abanonCustomInfo(abandonVo.getIds(), abandonVo.getReason()));
    }

    @Log(title = "认领客户", businessType = BusinessType.UPDATE)
    @GetMapping("/claimCustom/{ids}")
    public AjaxResult claimCustom(@PathVariable String[] ids)
    {
        return toAjax(customInfoService.claimCustomInfo(ids));
    }

    @Log(title = "客户交接", businessType = BusinessType.UPDATE)
    @PostMapping("/handoverCustom")
    public AjaxResult handoverCustomInfo(@RequestBody HandoverParamVo handoverParamVo)
    {
        return toAjax(customInfoService.handoverCustomInfo(handoverParamVo));
    }

    @Log(title = "意向标签", businessType = BusinessType.UPDATE)
    @GetMapping("/intentCustom/{id}")
    public AjaxResult intentCustom(@PathVariable String id) throws Exception {
        return toAjax(customInfoService.intentCustom(id));
    }

    @Log(title = "意向标签", businessType = BusinessType.UPDATE)
    @GetMapping("/intentCustoms/{ids}")
    public AjaxResult intentCustoms(@PathVariable String[] ids) throws Exception {
        return toAjax(customInfoService.intentCustoms(ids));
    }

    @Log(title = "签约客户", businessType = BusinessType.UPDATE)
    @GetMapping("/signCustom/{id}")
    public AjaxResult signCustom(@PathVariable String id) throws Exception {
        return toAjax(customInfoService.signCustom(id));
    }

    @Log(title = "签约客户", businessType = BusinessType.UPDATE)
    @GetMapping("/signCustoms/{ids}")
    public AjaxResult signCustoms(@PathVariable String[] ids) throws Exception {
        return toAjax(customInfoService.signCustoms(ids));
    }

    @Log(title = "分配运营人员", businessType = BusinessType.UPDATE)
    @PutMapping("/assignOperators")
    public AjaxResult assignOperators(@RequestBody CustomOperatorVo customOperatorVo)
    {
        List<CustomOperator> operatorList = new ArrayList<>();
        if(customOperatorVo.getCustomIds() != null && customOperatorVo.getCustomIds().length > 0){
            for(String customId : customOperatorVo.getCustomIds()){
                for(String operatorId : customOperatorVo.getOperators()){
                    CustomOperator operator = new CustomOperator();
                    operator.setCustomId(customId);
                    operator.setUserId(operatorId);
                    operatorList.add(operator);
                }
            }
        }

        return customInfoService.assignOperators(operatorList);
    }

    @Log(title = "转交店铺", businessType = BusinessType.UPDATE)
    @PutMapping("/transferOperators")
    public AjaxResult transferOperators(@RequestBody CustomOperatorVo customOperatorVo) throws Exception {
        List<CustomOperator> operatorList = new ArrayList<>();
        if(customOperatorVo.getCustomIds() != null && customOperatorVo.getCustomIds().length > 0){
            for(String customId : customOperatorVo.getCustomIds()){
                for(String operatorId : customOperatorVo.getOperators()){
                    CustomOperator operator = new CustomOperator();
                    operator.setCustomId(customId);
                    operator.setUserId(operatorId);
                    operatorList.add(operator);
                }
            }
        }

        return customInfoService.transferOperators(operatorList);
    }

    @PostMapping("/updateCustomOperStatus")
    public AjaxResult updateCustomOperStatus(@RequestBody CustomInfo customInfo)
    {
        return toAjax(customInfoService.updateCustomOperStatus(customInfo));
    }

    @GetMapping("/exportShop")
    public AjaxResult exportShop(CustomInfo customInfo) throws IOException {
        List<CustomInfo> list = customInfoService.selectLeaderShop(customInfo);
        String[] headerColumns = { "序号", "店铺名称", "旺旺号", "运营人员", "店铺账号", "店铺密码", "微信群", "开始操作日期", "流失/暂停日期", "店铺状态" };

        // 创建HSSFWorkbook对象-
        HSSFWorkbook wb = new HSSFWorkbook();
        OutputStream out = null;
        try {
            // 创建HSSFSheet对象
            HSSFSheet sheet = wb.createSheet("店铺信息");
            // 创建表头
            // 创建HSSFRow对象
            HSSFRow head = sheet.createRow(0);
            head.setHeight((short) (36 * 20));
            for (int i = 0; i < headerColumns.length; i++) {
                // 创建HSSFCell对象
                HSSFCell cell = head.createCell(i);
                cell.setCellStyle(createHeaderRowStyle(wb));
                cell.setCellValue(headerColumns[i]);
                switch (i){
                    case 0:
                        sheet.setColumnWidth(i,  7* 256);
                        break;
                    case 1:
                        sheet.setColumnWidth(i, 30 * 256);
                        break;
                    case 2:
                        sheet.setColumnWidth(i, 30 * 256);
                        break;
                    case 3:
                        sheet.setColumnWidth(i, 30 * 256);
                        break;
                    case 4:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 5:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 6:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 7:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 8:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 9:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                }
            }

            // 写数据
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    HSSFRow row = sheet.createRow(i + 1);
                    // 设置行高 20 * 20
                    row.setHeight((short) 400);
                    for (int j = 0; j < headerColumns.length; j++) {
                        HSSFCell cell = row.createCell(j);
                        switch (j) {
                            case 0:
                                cell.setCellStyle(createData2RowStyle(wb));
                                cell.setCellValue(i + 1);
                                break;
                            case 1:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getCusname());
                                break;
                            case 2:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getAliww());
                                break;
                            case 3:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getOperators());
                                break;
                            case 4:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getAccount());
                                break;
                            case 5:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getPassword());
                                break;
                            case 6:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getWechatGroup());
                                break;
                            case 7:
                                cell.setCellStyle(createData1RowStyle(wb));
                                if(list.get(i).getOperStartDate() != null) {
                                    cell.setCellValue(DateUtils.parseDateToStr("yyyy-MM-dd", list.get(i).getOperStartDate()));
                                }
                                break;
                            case 8:
                                cell.setCellStyle(createData2RowStyle(wb));
                                if(list.get(i).getOperEndDate() != null){
                                    cell.setCellValue(DateUtils.parseDateToStr("yyyy-MM-dd", list.get(i).getOperEndDate()));
                                }
                                break;
//                            case 7:
//                                cell.setCellStyle(createData2RowStyle(wb));
//                                if(list.get(i).getOperEndDate() != null){
//                                    cell.setCellValue(DateUtils.parseDateToStr("yyyy-MM-dd", list.get(i).getOperEndDate()));
//                                }
//                                break;
                            case 9:
                                cell.setCellStyle(createData2RowStyle(wb));
                                if ("0".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("未开始");
                                } else if ("1".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("操作中");
                                } else if ("2".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("已暂停");
                                } else if ("3".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("已流失");
                                }
                                break;
                        }

                    }
                }
            }
            String filename = "店铺信息_" + DateUtils.dateTimeNow("yyyyMMddHHmmss") + ".xlsx";
            out = new FileOutputStream(getAbsoluteFile(filename));
            wb.write(out);
            return AjaxResult.success(filename);
        }catch(Exception e)
        {
            throw new CustomException("导出Excel失败，请联系网站管理员！");
        }finally
        {
            if (wb != null)
            {
                try
                {
                    wb.close();
                }
                catch (IOException e1)
                {
                    e1.printStackTrace();
                }
            }
            if (out != null)
            {
                try
                {
                    out.close();
                }
                catch (IOException e1)
                {
                    e1.printStackTrace();
                }
            }
        }
    }

    @GetMapping("/exportShopAccordOperator")
    public AjaxResult exportShopAccordOperator(CustomInfo customInfo) throws IOException {
        List<CustomInfo> list = customInfoService.selectShopAccordOperator(customInfo);
        String[] headerColumns = { "序号", "店铺名称", "旺旺号", "运营人员", "店铺账号", "店铺密码", "微信群", "开始操作日期", "流失/暂停日期", "店铺状态" };

        // 创建HSSFWorkbook对象-
        HSSFWorkbook wb = new HSSFWorkbook();
        OutputStream out = null;
        try {
            // 创建HSSFSheet对象
            HSSFSheet sheet = wb.createSheet("店铺信息");
            // 创建表头
            // 创建HSSFRow对象
            HSSFRow head = sheet.createRow(0);
            head.setHeight((short) (36 * 20));
            for (int i = 0; i < headerColumns.length; i++) {
                // 创建HSSFCell对象
                HSSFCell cell = head.createCell(i);
                cell.setCellStyle(createHeaderRowStyle(wb));
                cell.setCellValue(headerColumns[i]);
                switch (i){
                    case 0:
                        sheet.setColumnWidth(i,  7* 256);
                        break;
                    case 1:
                        sheet.setColumnWidth(i, 30 * 256);
                        break;
                    case 2:
                        sheet.setColumnWidth(i, 30 * 256);
                        break;
                    case 3:
                        sheet.setColumnWidth(i, 30 * 256);
                        break;
                    case 4:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 5:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 6:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 7:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 8:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                    case 9:
                        sheet.setColumnWidth(i, 20 * 256);
                        break;
                }
            }

            // 写数据
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    HSSFRow row = sheet.createRow(i + 1);
                    // 设置行高 20 * 20
                    row.setHeight((short) 400);
                    for (int j = 0; j < headerColumns.length; j++) {
                        HSSFCell cell = row.createCell(j);
                        switch (j) {
                            case 0:
                                cell.setCellStyle(createData2RowStyle(wb));
                                cell.setCellValue(i + 1);
                                break;
                            case 1:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getCusname());
                                break;
                            case 2:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getAliww());
                                break;
                            case 3:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getOperators());
                                break;
                            case 4:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getAccount());
                                break;
                            case 5:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getPassword());
                                break;
                            case 6:
                                cell.setCellStyle(createData1RowStyle(wb));
                                cell.setCellValue(list.get(i).getWechatGroup());
                                break;
                            case 7:
                                cell.setCellStyle(createData1RowStyle(wb));
                                if(list.get(i).getOperStartDate() != null) {
                                    cell.setCellValue(DateUtils.parseDateToStr("yyyy-MM-dd", list.get(i).getOperStartDate()));
                                }
                                break;
                            case 8:
                                cell.setCellStyle(createData2RowStyle(wb));
                                if(list.get(i).getOperEndDate() != null){
                                    cell.setCellValue(DateUtils.parseDateToStr("yyyy-MM-dd", list.get(i).getOperEndDate()));
                                }
                                break;
//                            case 7:
//                                cell.setCellStyle(createData2RowStyle(wb));
//                                if(list.get(i).getOperEndDate() != null){
//                                    cell.setCellValue(DateUtils.parseDateToStr("yyyy-MM-dd", list.get(i).getOperEndDate()));
//                                }
//                                break;
                            case 9:
                                cell.setCellStyle(createData2RowStyle(wb));
                                if ("0".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("未开始");
                                } else if ("1".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("操作中");
                                } else if ("2".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("已暂停");
                                } else if ("3".equals(list.get(i).getOperStatus())) {
                                    cell.setCellValue("已流失");
                                }
                                break;
                        }

                    }
                }
            }
            String filename = "店铺信息_" + DateUtils.dateTimeNow("yyyyMMddHHmmss") + ".xlsx";
            out = new FileOutputStream(getAbsoluteFile(filename));
            wb.write(out);
            return AjaxResult.success(filename);
        }catch(Exception e)
        {
            throw new CustomException("导出Excel失败，请联系网站管理员！");
        }finally
        {
            if (wb != null)
            {
                try
                {
                    wb.close();
                }
                catch (IOException e1)
                {
                    e1.printStackTrace();
                }
            }
            if (out != null)
            {
                try
                {
                    out.close();
                }
                catch (IOException e1)
                {
                    e1.printStackTrace();
                }
            }
        }
    }

    private String getAbsoluteFile(String filename)
    {
        String downloadPath = RuoYiConfig.getDownloadPath() + filename;
        File desc = new File(downloadPath);
        if (!desc.getParentFile().exists())
        {
            desc.getParentFile().mkdirs();
        }
        return downloadPath;
    }

    private HSSFCellStyle createHeaderRowStyle(HSSFWorkbook wb)
    {
        // 设置字体
        HSSFFont font = wb.createFont();
        //设置字体大小
        font.setFontHeightInPoints((short) 10);
        //字体加粗
        font.setBold(true);
        //设置字体名字
        font.setFontName("宋体");

        //设置样式;
        HSSFCellStyle style = wb.createCellStyle();
        //设置底边框;
        style.setBorderBottom(BorderStyle.THIN);
        //设置底边框颜色;
        style.setBottomBorderColor(IndexedColors.BLACK.index);
        //设置左边框;
        style.setBorderLeft(BorderStyle.THIN);
        //设置左边框颜色;
        style.setLeftBorderColor(IndexedColors.BLACK.index);
        //设置右边框;
        style.setBorderRight(BorderStyle.THIN);
        //设置右边框颜色;
        style.setRightBorderColor(IndexedColors.BLACK.index);
        //设置顶边框;
        style.setBorderTop(BorderStyle.THIN);
        //设置顶边框颜色;
        style.setTopBorderColor(IndexedColors.BLACK.index);
        //在样式用应用设置的字体;
        style.setFont(font);
        //设置自动换行;
        style.setWrapText(false);
        //设置水平对齐的样式为居中对齐;
        style.setAlignment(HorizontalAlignment.CENTER);
        //设置垂直对齐的样式为居中对齐;
        style.setVerticalAlignment(VerticalAlignment.CENTER);

        style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN1.getIndex());
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        return style;
    }

    private HSSFCellStyle createData1RowStyle(HSSFWorkbook wb)
    {
        // 设置字体
        HSSFFont font = wb.createFont();
        //设置字体大小
        font.setFontHeightInPoints((short) 10);
        //字体加粗
        font.setBold(false);
        //设置字体名字
        font.setFontName("宋体");

        //设置样式;
        HSSFCellStyle style = wb.createCellStyle();
        //设置底边框;
        style.setBorderBottom(BorderStyle.THIN);
        //设置底边框颜色;
        style.setBottomBorderColor(IndexedColors.BLACK.index);
        //设置左边框;
        style.setBorderLeft(BorderStyle.THIN);
        //设置左边框颜色;
        style.setLeftBorderColor(IndexedColors.BLACK.index);
        //设置右边框;
        style.setBorderRight(BorderStyle.THIN);
        //设置右边框颜色;
        style.setRightBorderColor(IndexedColors.BLACK.index);
        //设置顶边框;
        style.setBorderTop(BorderStyle.THIN);
        //设置顶边框颜色;
        style.setTopBorderColor(IndexedColors.BLACK.index);
        //在样式用应用设置的字体;
        style.setFont(font);
        //设置自动换行;
        style.setWrapText(false);
        //设置水平对齐的样式为居中对齐;
        style.setAlignment(HorizontalAlignment.LEFT);
        //设置垂直对齐的样式为居中对齐;
        style.setVerticalAlignment(VerticalAlignment.CENTER);

        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        return style;
    }

    private HSSFCellStyle createData2RowStyle(HSSFWorkbook wb)
    {
        // 设置字体
        HSSFFont font = wb.createFont();
        //设置字体大小
        font.setFontHeightInPoints((short) 10);
        //字体加粗
        font.setBold(false);
        //设置字体名字
        font.setFontName("宋体");

        //设置样式;
        HSSFCellStyle style = wb.createCellStyle();
        //设置底边框;
        style.setBorderBottom(BorderStyle.THIN);
        //设置底边框颜色;
        style.setBottomBorderColor(IndexedColors.BLACK.index);
        //设置左边框;
        style.setBorderLeft(BorderStyle.THIN);
        //设置左边框颜色;
        style.setLeftBorderColor(IndexedColors.BLACK.index);
        //设置右边框;
        style.setBorderRight(BorderStyle.THIN);
        //设置右边框颜色;
        style.setRightBorderColor(IndexedColors.BLACK.index);
        //设置顶边框;
        style.setBorderTop(BorderStyle.THIN);
        //设置顶边框颜色;
        style.setTopBorderColor(IndexedColors.BLACK.index);
        //在样式用应用设置的字体;
        style.setFont(font);
        //设置自动换行;
        style.setWrapText(false);
        //设置水平对齐的样式为居中对齐;
        style.setAlignment(HorizontalAlignment.CENTER);
        //设置垂直对齐的样式为居中对齐;
        style.setVerticalAlignment(VerticalAlignment.CENTER);

        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        return style;
    }
}
